﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CH.TestData.Common;
using System.Threading;

namespace CH.TestData.Generate
{
    public class MsSqlTextGenerate : AbstractGenerate
    {

        public override void Start(int count, string tableName, List<string> columns, List<IDataProvider> list)
        {
            
            StringBuilder sb = new StringBuilder("");
            StringBuilder prefix = new StringBuilder("INSERT INTO " + tableName+" (");

            for (int i = 0; i < columns.Count; i++)
            {
                prefix.Append("[" + columns[i] + "]");
                if (i != columns.Count - 1)
                {
                    prefix.Append(",");
                }
            }

            prefix.Append(") Values ");


            for (int i = 0; i < count; i++)
            {
                StringBuilder item = new StringBuilder(prefix.ToString()+"(");
                for (int j = 0; j < list.Count; j++)
                {
                    
                    item.Append(list[j].GetNextValue());
                    if (j != list.Count - 1) 
                    {
                        item.Append(",");
                    }
                }
                item.Append(")");
                sb.Append(item.ToString());
                sb.Append(Environment.NewLine);
                base.AbstractGenerate_GenerateUpdateEvent("");
            }
            base.AbstractGenerate_GenerateCompleteEvent(sb.ToString());
        }
    }
}
